package com.example.administrator.shzs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.administrator.shzs.R;
import com.example.administrator.shzs.entity.Integral;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * 积分列表 XrecycleAdapter
 * Created by Administrator on 2016/10/25.
 */
public class IntegralXrecycleviewAdapter extends RecyclerView.Adapter<IntegralXrecycleviewAdapter.VideoHolderr> {

    private List<Integral> datalist;
    private Context context;

    public IntegralXrecycleviewAdapter(List<Integral> datalist, Context context) {
        this.datalist = datalist;
        this.context = context;
    }


    public interface IntegralItem {
        void Onclik(View view, int postion);
    }
    private IntegralItem integralItem;

    public void setIntegralItem(IntegralItem listent) {
        this.integralItem = listent;
    }

    @Override
    public IntegralXrecycleviewAdapter.VideoHolderr onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.integraxrecycle_item, null);
        VideoHolderr videoHolderr = new VideoHolderr(view);
        return videoHolderr;
    }

    @Override
    public void onBindViewHolder(final VideoHolderr holder, final int position) {

        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.loding)
                .showImageForEmptyUri(R.mipmap.loding)
                .showImageOnFail(R.mipmap.loding)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();
        ImageLoader.getInstance().displayImage(datalist.get(position).getPicture(),
                holder.imageView, options);

        holder.Titlee.setText(datalist.get(position).getGname());
        holder.Number.setText(datalist.get(position).getStocks());
        holder.Money.setText(datalist.get(position).getGiftsPrice());
        holder.Intergra.setText(datalist.get(position).getNeedIntegral());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              integralItem.Onclik(holder.itemView,position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return datalist == null ? 0 : datalist.size();
    }


    class VideoHolderr extends RecyclerView.ViewHolder {

        private ImageView imageView;
        private TextView Titlee;
        private TextView Money;
        private TextView Number;
        private TextView Intergra;

        public VideoHolderr(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.image);
            Titlee = (TextView) itemView.findViewById(R.id.Titlee);
            Money = (TextView) itemView.findViewById(R.id.Money);
            Number = (TextView) itemView.findViewById(R.id.Number);
            Intergra = (TextView) itemView.findViewById(R.id.Intergra);

        }
    }
}
